<template>
    <div class="athPage">
        <div class="header">
            <div class="container">
                <div class="logo">
                    <div class="icon">
                        <img :src="logoImg" alt="">
                    </div>
                    <div class="title">{{sysTitle}}</div>
                </div>
                <div class="matchInfo">
                    <div class="master">{{matchInfo.EventName}}</div>
                    <div class="sub">{{matchInfo.PhaseName}}</div>
                </div>
                <div class="acs" >
                    <ul class="lstTopAcs">
                        <li @click="getAths">
                            <i class="fa fa-refresh"></i> 刷新
                        </li>
                        <li @click="goBack">
                            <i class="fa fa-reply"></i> 返回
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="body container" id="athBody">
            <div class="lstAths" :style="'height:'+athsHeight+'px'">
                <div 
                    v-for="(ath , athIndex) in aths.items"
                    :key = "athIndex"
                    class="liAth"
                    @click="goAth(athIndex)"
                >
                    <div class="player" style="text-align:right">
                        <div class="name">{{ath.HomeDelegation}} {{ath.HomeName}}</div>
                    </div>
                    <div class="vs">vs</div>
                    <div class="player" style="text-align:left">
                        <div class="name">{{ath.AwayName}} {{ath.AwayDelegation}} </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        mounted() {
            var me = this;
            try{
                me.$nextTick().then(_=>{
                    me.init();
                });
            }
            catch(er){
                console.log(er);
            }
        },
        data() {
            return {
                logoImg:require("../res/imgs/logo.png"),
                sysTitle:"击剑记分器",   
                athsHeight:200,
                matchInfo:{},
                aths: {
                    items:[]
                },
            };
        },
        methods: {
            init() {
                var me = this;
                try{
                    me.resize();
                    me.matchInfo = me.$route.query;
                    me.getAths();
                }
                catch(er){
                    console.log(er);
                }                
            },
            resize() {
                var me = this;
                try{
                    var h = document.getElementById('athBody').offsetHeight; 
                    me.athsHeight = h-30; 
                }
                catch(er){
                    console.log(er);
                }                
            }, 
            goBack() {
                var me = this;
                try{
                    me.$router.back();
                }
                catch(er){
                    console.log(er);
                }                
            }, 
            goAth (athIndex) {
                var me = this;
                try{
                    if ( me.aths!=null && me.aths.items!=null && me.aths.items.length>0){
                        var athInfo = me.aths.items[athIndex];
                        athInfo.matchType = me.matchInfo.MatchType;
                        athInfo.eventName = me.matchInfo.EventName;
                        athInfo.phaseName = me.matchInfo.PhaseName;
                        me.$router.push({
                            path:"tsInfo",
                            query: athInfo
                        });
                    }
                }
                catch(er){
                    console.log(er);
                }                
            }, 
            getAths() {
                var me = this;
                return new Promise((success,faild)=>{
                    try{
                        var key = "fe2023/ts/getAths";
                        var ps={
                            matchId:me.matchInfo.MatchID,
                            matchType: me.matchInfo.MatchType
                        };
                        me.feSys.query(key , ps).then(res=>{
                            console.log(res);                            
                            var items = [];
                            if( res && res!=null && res.length>0){
                                items = res;
                            }
                            me.aths.items = items;
                            success();
                        })
                    }
                    catch(er){
                        console.log(er);
                        success();
                    }   
                });             
            },
        },
        
    }
</script>

<style lang="less" scoped>
    @import url('./fe.less');
    .athPage{
        height: 100%;
        background-color: #0b4383;
        color: #fff;
        display: flex;
        flex-direction: column;
        .header{
            border-bottom: 2px solid #0077fe;
            .container{                
                display: flex;
                justify-content: space-between;
                align-items: center;
                .logo{
                    display: flex;
                    padding: 10px;
                    align-items: center;
                    .icon{
                        height: 40px; 
                        img{
                            height: 100%;
                            background-color: #fff;
                            padding: 5px;
                            border-radius: 2px;
                        }
                    }
                    .title{
                        padding-left:15px;
                        font-weight: bold;
                        font-size: 1.2em;
                    }
                }

                .matchInfo{
                    text-align: center;
                }

                .acs{
                    ul.lstTopAcs{
                        display: flex;
                        align-items: center;
                        li{
                            height: 32px;
                            line-height: 32px;
                            width: 79px;
                            text-align: center;
                            margin-left: 15px;
                            background-color: #0077fe;
                        }
                        li:active{
                            background-color: #318bf3;
                        }
                    }
                }
            }
        }

        .body{
            flex: 1;
            padding: 15px;
            display: flex;
            flex-direction: column;

            .lstAths{
                overflow-y: auto;
                .liAth{
                    background-color: #0077fe;
                    display: flex;
                    align-items: center; 
                    font-size: 1.2em;
                    padding: 15px 0;
                    margin-bottom: 5px;
                    .player{
                        width: 40%;
                    }              
                    .vs{
                        flex: 1;
                        text-align: center;
                        color: #f5f110;
                        font-size: 1.2em;
                    }      
                }
                .liAth:active{
                    background-color: #318bf3;
                }
            }
            
            .lstAths::-webkit-scrollbar{
                width: 18px;
                height: 108px;
            }
            .lstAths::-webkit-thumb{
                background-color: rgb(24, 24, 39);
                border-radius: 10px;
            }
        }
    }

</style>